<%@ page contentType="text/html;charset=UTF-8" import="java.sql.*" language="java" %>
<%@ page import="java.io.*,java.util.*" %>
<%
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    String gender = request.getParameter("gender");
    String phone = request.getParameter("phone");

    if(id == null || name == null || gender == null || phone == null || id.trim().isEmpty() || name.trim().isEmpty() || gender.trim().isEmpty() || phone.trim().isEmpty()) {
        out.println("<script>alert('请填写所有空缺'); window.location='increase_info.jsp';</script>");
    } else {
        String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        String DB_URL = "jdbc:mysql://localhost:3306/sims";
        String USER = "root";
        String PASS = "123456";
        Class.forName(JDBC_DRIVER);
        Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
        String sql = "INSERT into student(id,name,gender,phone) VALUES (?,?,?,?)";
        PreparedStatement psmt = conn.prepareStatement(sql);
        psmt.setInt(1,Integer.parseInt(id));
        psmt.setString(2,name);
        psmt.setString(3,gender);
        psmt.setString(4, phone);
        int rs=psmt.executeUpdate();
        conn.close();
        response.sendRedirect("index.jsp");
    }
%>
